﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace MiniSudokuWeb
{
    /// <summary>
    /// Summary description for NewPuzzleService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class NewPuzzleService : System.Web.Services.WebService
    {
        [WebMethod]
        public List<int[]> GetNewPuzzleData()
        {
            List<int[]> result = new List<int[]>();

            var squares = new[] {new[] {0, 0}, new[] {0, 1}, new[] {1, 0}, new[] {1, 1}}.ToList();
            var values = new[] {1, 2, 3, 4}.ToList();

            Random random = new Random();
            for (int i = 0; i < 2; i++)
            {
                var coordinates = squares[random.Next(0, squares.Count)];
                squares.Remove(coordinates);

                var value = values[random.Next(0, values.Count)];
                values.Remove(value);

                result.Add(new[] { coordinates[0], coordinates[1], value });
            }
            return result;
        }
    }
}
